<template>
  <div class="banner">
    <div class="item">
      <!-- <img :src="dataList[currentIndex].pictureUtl" /> -->
    </div>
    <div v-if="dataList.length > 1" class="page">
      <ul>
        <li @click="gotoPage(prevIndex)">&lt;</li>
        <li
          v-for="(item, index) in dataList"
          :key="index"
          :class="{ current: currentIndex == index }"
          @click="gotoPage(index)"
        >
          <img :src="item.pictureUtl" />
        </li>
        <!-- <li></li> -->
        <li @click="gotoPage(nextIndex)">&gt;</li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    // nowwidth: {
    //   type: String,
    //   default: () => "500px"
    // },
    // nowheight: {
    //   type: String,
    //   default: () => "220px"
    // },
    datat: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      dataList: [],
      currentIndex: 0 // 默认显示图片
    };
  },
  computed: {
    // 上一张
    prevIndex() {
      if (this.currentIndex === 0) {
        return this.dataList.length - 1;
      } else {
        return this.currentIndex - 1;
      }
    },
    // 下一张
    nextIndex() {
      if (this.currentIndex === this.dataList.length - 1) {
        return 0;
      } else {
        return this.currentIndex + 1;
      }
    }
  },
  mounted() {
    // console.log(this.dataList[0].pictureUtl)
    // this.gotoPage(0)
    this.datatsetTime();
  },
  methods: {
    datatsetTime() {
      setTimeout(() => {
        this.dataList = this.datat;
        // console.log(this.dataList);
      }, 600);
    },
    gotoPage(index) {
      this.currentIndex = index;
    }
  }
};
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}
ul li {
  list-style: none;
  /* float: left; */
  width: 100%;
  height: 100%;
  /* line-height: 100px; */
  text-align: center;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.8);
  font-size: 14px;
}
.banner {
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  margin-top: 60px;
}
.banner .page img {
  width: 100px;
  height: 100px;
  display: block;
}
.banner .page {
  background: rgba(0, 0, 0, 0.5);
  position: absolute;
  /* right: 0;
  bottom: 0; */
  width: 100%;
  height: 100%;
}
.banner .page ul {
  /* float: right; */
  display: flex;
  width: 100%;
  height: 100%;
}
.current {
  color: #ff6700;
}
</style>
